.TH std::is_placeholder 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::is_placeholder \- std::is_placeholder

.SH Synopsis
   Defined in header <functional>
   template< class T >             \fI(since C++11)\fP
   struct is_placeholder;

   If T is the type of a standard placeholder (_1, _2, _3, ...), then this template is
   derived from std::integral_constant<int, 1>, std::integral_constant<int, 2>,
   std::integral_constant<int, 3>, respectively.

   If T is not a standard placeholder type, this template is derived from
   std::integral_constant<int, 0>.

   A program may specialize this template for a program-defined type T to implement
   UnaryTypeTrait with base characteristic of std::integral_constant<int, N> with
   positive N to indicate that T should be treated as N^th placeholder type.

   std::bind uses std::is_placeholder to detect placeholders for unbound arguments.

.SH Member constants

   value    placeholder value or 0 for non-placeholder types
   \fB[static]\fP \fI(public static member constant)\fP

.SH Member functions

   operator int converts the object to int, returns value
                \fI(public member function)\fP
   operator()   returns value
   \fI(C++14)\fP      \fI(public member function)\fP

.SH Member types

   Type       Definition
   value_type int
   type       std::integral_constant<int, value>

.SH Example


// Run this code

 #include <functional>
 #include <iostream>
 #include <type_traits>

 struct My_2 {} my_2;

 namespace std
 {
     template<>
     struct is_placeholder<My_2> : public integral_constant<int, 2> {};
 }

 int f(int n1, int n2)
 {
     return n1 + n2;
 }

 int main()
 {
     std::cout << "Standard placeholder _5 is for the argument number "
               << std::is_placeholder_v<decltype(std::placeholders::_5)>
               << '\\n';

     auto b = std::bind(f, my_2, 2);
     std::cout << "Adding 2 to 11 selected with a custom placeholder gives "
               << b(10, 11) // the first argument, namely 10, is ignored
               << '\\n';
 }

.SH Output:

 Standard placeholder _5 is for the argument number 5
 Adding 2 to 11 selected with a custom placeholder gives 13

.SH See also

   bind                binds one or more arguments to a function object
   \fI(C++11)\fP             \fI(function template)\fP
   _1, _2, _3, _4, ... placeholders for the unbound arguments in a std::bind expression
   \fI(C++11)\fP             (constant)
